import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { WorkorderPartsVO, WorkorderPartsForm, WorkorderPartsQuery } from '@/api/workorder/workorderParts/types';
import { Accessory, WorkorderInfoVO } from '@/api/workorder/workorderInfo/types';

/**
 * 查询工单更换备件列表
 * @param query
 * @returns {*}
 */

export const listWorkorderParts = (query?: WorkorderPartsQuery): AxiosPromise<WorkorderPartsVO[]> => {
  return request({
    url: '/workorder/workorderParts/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询工单更换备件详细
 * @param id
 */
export const getWorkorderParts = (id: string | number): AxiosPromise<WorkorderPartsVO> => {
  return request({
    url: '/workorder/workorderParts/' + id,
    method: 'get'
  });
};

/**
 * 新增工单更换备件
 * @param data
 */
export const addWorkorderParts = (data: WorkorderPartsForm) => {
  return request({
    url: '/workorder/workorderParts',
    method: 'post',
    data: data
  });
};

/**
 * 修改工单更换备件
 * @param data
 */
export const updateWorkorderParts = (data: WorkorderPartsForm) => {
  return request({
    url: '/workorder/workorderParts',
    method: 'put',
    data: data
  });
};

/**
 * 删除工单更换备件
 * @param id
 */
export const delWorkorderParts = (id: string | number | Array<string | number>) => {
  return request({
    url: '/workorder/workorderParts/' + id,
    method: 'delete'
  });
};
export const workorderParts2partsRequipment = (id: string | number): AxiosPromise<WorkorderPartsVO> => {
  return request({
    url: '/workorder/workorderParts/workorderParts2partsRequipment/' + id,
    method: 'get'
  });
};
/**
 * 详情
 * @param workorderId
 */
export const getDetailWorkorderParts = (workorderId: string | number): AxiosPromise<WorkorderPartsVO> => {
  return request({
    url: '/workorder/workorderInfo/detail/' + workorderId,
    method: 'get'
  });
};